﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Enterprise.Infrastructure;
using Enterprise.Model.User;
using Enterprise.Data.User;
namespace Enterprise.Service.User
{
    /// <summary>
    ///  用户对应部门职务表业务服务
    /// </summary>
    public class UserDepartmentService
    {

        /// <summary>
        /// 用户对应部门职务缓存标记
        /// </summary>
        private static string cacheKey = "Enterprise-UserDeparment";

        /// <summary>
        /// 用户对应部门职务列表 返回所有记录
        /// </summary>
        /// <returns></returns>
        public List<UserDeparmentEntity> UserDepartmentList()
        {
            if (CacheHelper.Contains(cacheKey))
            {
                return (List<UserDeparmentEntity>)CacheHelper.GetCache(cacheKey);
            }
            else
            {
                UserDepartmentData data = new UserDepartmentData();
                List<UserDeparmentEntity> list = data.UserDepartmentList();
                CacheHelper.Add(cacheKey, list);
                return list;
            }
        }

        /// <summary>
        /// 用户对应部门职务表操作 添加、修改、删除
        /// </summary>
        /// <param name="entity">用户实体</param>
        public void UserDepartmentExecute(UserDeparmentEntity entity)
        {
            string cmd = string.Empty;
            switch (entity.DB_Option_Action)
            {
                case "Insert":
                    cmd = "Insert into SYS_USERDEPT(USERID,DEPTID,CORRELATION) values(" + entity.USERID + "," + entity.DEPTID + ",'" + entity.CORRELATION + "')";
                    break;
                case "Update":
                    cmd = "Update SYS_USERDEPT set CORRELATION='" + entity.CORRELATION + "' where USERID=" + entity.USERID + " and DEPTID=" + entity.DEPTID;
                    break;
                case "Delete":
                    cmd = "Delete from SYS_USERDEPT where USERID=" + entity.USERID + " and DEPTID=" + entity.DEPTID;
                    break;
            }
            if (!string.IsNullOrEmpty(cmd))
            {
                UserDepartmentExecuteBySql(cmd);
            }
        }

        /// <summary>
        /// 人员操作  
        /// </summary>
        /// <param name="cmd">sql语句</param>
        public void UserDepartmentExecuteBySql(string cmd)
        {
            UserDepartmentData data = new UserDepartmentData();
            data.UserDepartmentExecute(cmd);
        }

    }
}
